<template>
  <div>
    <div class="top_Dropdo">
      <div class="top-cell">
        <div @click="props = !props">全部科室</div>
        <div>全国</div>
        <div>默认排序</div>
      </div>
    </div>
    <div class="propsnav" v-if="props">
      <div class="tab-container">
        <div class="tabs">
          <div v-for="(item, index) in listarr" :key="index" @click="changeindex(item, index)" :class="indexs == index ? 'bg' : ''">
            {{ item.adminname }}
          </div>
        </div>
        <div class="rigth">
          <div v-for="(item, index) in citylist" :key="index">
            <div v-if="item.adminname == titles">
              <div class="right-key" @click="routerKey(item)">{{ item.adminchildrenname }}</div>
            </div>
          </div>
          <div v-if="titles == '全部'">
            <div class="right-key">全部科室</div>
          </div>
        </div>
      </div>
    </div>
    <div>
      <div v-if="loading">Loading...</div>
      <!-- 判断状态为空时展示 -->
      <div v-if="show">
        <van-empty description="无可用数据">
          <van-button class="btn">健康科普</van-button>
          <van-button class="btn" @click="zhuan">咨询专家</van-button>
          <van-button class="btn" @click="gua">医院挂号</van-button>
          <van-button class="btn">线上购药</van-button>
          <span @click="feedback" class="feedback">我要反馈</span>
        </van-empty>
      </div>
      <!-- 数据不为空时展示 -->
      <div v-if="!show">
        <div class="physician" v-for="(item, index) in list" :key="index">
          <img :src="item.doctorimage" v-lazy="item.doctorimage" class="image" />
          <div class="physicians">
            <div class="warp1">
              <h4>{{ item.doctorname }}</h4>
              <div>{{ item.doctorstate }}</div>
            </div>
            <div>{{ item.doctorcity }} {{ item.doctoradministre }}</div>
            <div class="navs">
              <div>图文咨询</div>
              <div>电话咨询</div>
              <div>视频咨询</div>
            </div>
            <div class="titletext">擅长:{{ item.doctordescword }}</div>
            <span class="reviews"
              >好评率 <span class="color">{{ item.doctorgood }}%</span> | 锦旗 <span class="color">{{ item.doctortime }}</span> | 浏览人次 <span class="color">{{ item.doctorbrowse }}</span></span
            >
            <div class="num">
              <div>￥{{ item.doctorprice }} <span>起</span></div>
              <div class="doct" @click="doctor(item)">问医生</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
// import axios from 'axios';
const value1 = ref(0);
const value2 = ref('a');
const router = useRouter();
const value3 = ref('b');
const data = ref([]);
const props = ref(false);

const loading = ref(true);
import axios from '@/utils/axios/axios';
const show = ref(false);
const list = ref([]);
const route = useRoute();
const citylist = ref([]);
const listarr = ref([]);
const indexs = ref(0);
const titles = ref('全部');
const items = ref(JSON.parse(route.query.items));
const SearchQuery = ref('');
// 判断是否存在后端数据如果有xaios传到前端
const userlist = async () => {
  await axios.get('/api/doctorlist').then((res) => {
    SearchQuery.value = items.value;
    list.value = res.data.res.filter((s) => s.doctorname.includes(SearchQuery.value));
  });
};
userlist();
// 判断是否存在后端数据如果有xaios传到前端
const citysuser = async () => {
  await axios.get('/api/tabsql').then((res) => {
    console.log(res);
    citylist.value = res.data.res;
  });
};
citysuser();
const tabsql = async () => {
  await axios.get('/api/sort').then((res) => {
    console.log(res);
    listarr.value = res.data.res;
  });
};
tabsql();
const routerKey = (item: object) => {
  console.log(item.adminchildrenname);
  props.value=false
   list.value = list.value.filter((s) => s.doctoradministre==item.adminchildrenname);
 
   console.log(list.value);
 
};
const changeindex = (item: object, index: number) => {
  indexs.value = index;
  titles.value = item.adminname;
};
onMounted(async () => {
  try {
    // const response = await axios.get('https://api.example.com/data');
    // data.value = response.data;
  } catch (error) {
    console.error('Error fetching data:', error);
  } finally {
    loading.value = false;
  }
});
const doctor = (item) => {
  const items = JSON.stringify(item);
  router.push('/askdoctor?item=' + items);
};
// 咨询专家
const zhuan = () => {
  router.push('/layout/popular');
};
// 医院挂号
const gua = () => {
  router.push('/layout/appointment');
};
// 下拉表单
const option1 = [
  { text: '全部商品', value: 0 },
  { text: '新款商品', value: 1 },
  { text: '活动商品', value: 2 }
];
const option2 = [
  { text: '全部商品', value: 'a' },
  { text: '新款商品', value: 'b' },
  { text: '活动商品', value: 'c' }
];
const option3 = [
  { text: '全部商品', value: 'a' },
  { text: '新款商品', value: 'b' },
  { text: '活动商品', value: 'c' }
];
const Xiang = () => {
  console.log(111);
};
</script>

<style scoped lang="scss">
.list-item {
  width: 90%;
  height: 18vh;
  background: #d2e9eb;
  border-radius: 10px;
}
.propsnav {
  width: 93%;
  height: 100vh;
  background: #fff;
  margin: auto;
  position: fixed;
  top: 150px;
  left: 30px;
  z-index: 9999;
}
.btn {
  width: 80px;
  height: 30px;
  float: left;
  border: none;
  border: 1px solid blue;
  color: blue;
  border-radius: 10px;
  font-size: 12px;
  margin-left: 5px;
}

.feedback {
  color: blue;
  font-size: 14px;
  border-bottom: 2px solid blue;
  position: absolute;
  top: 80%;
  left: 42%;
}

.listTab2 {
  text-align: center;
}

.top_Dropdo {
  width: 100%;
  height: 8vh;
  .top-cell {
    display: flex;
    justify-content: space-around;
    height: 50px;
    line-height: 50px;
    font-size: 0.4rem;
  }
}

.top_Dropdo li {
  width: 30%;
  height: 100%;
  float: left;
  text-align: center;
  line-height: 8vh;
  margin-left: 9px;
}
.Main_list_nav {
  width: 100%;
  height: 100vh;
}

.Main_listtab {
  width: 100%;
  height: 26vh;
  margin-top: 10px;
  border: 1px solid #ccc;
  border-radius: 15px;
  overflow: hidden;
}

.Main_lift_tu {
  width: 20%;
  height: 100%;
  float: left;
}

.Main_lift_tu img {
  width: 80%;
  height: 30%;
  margin-left: 10%;
  margin-top: 7%;
  border-radius: 100%;
}

.Main_right_tit {
  width: 80%;
  height: 100%;
  float: left;
  padding: 4px;
  font-size: 14px;
  line-height: 3vh;
}

.zixun {
  width: 100%;
  height: 4vh;
}

.zixun li {
  float: left;
  font-size: 12px;
  width: 20%;
  margin-left: 6%;
  height: 100%;
  line-height: 4vh;
  text-align: center;
  border-radius: 5px;
}

.wen {
  width: 24vw;
  height: 5vh;
  float: right;
  background: rgb(92, 153, 234);
  border: none;
  color: #fff;
  border-radius: 10px;
}
.physician {
  display: flex;
  width: 93%;
  margin: auto;
  clear: both;
  font-size: 0.3rem;
  margin: 5px;

  .image {
    width: 50px;
    height: 50px;
    border-radius: 50px;
    margin: 15px;
  }

  .physicians {
    width: 250px;
    height: 190px;
    margin: auto;
    // margin-left: 2px;
    .titletext {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      /* 限制显示的行数 */
      -webkit-box-orient: vertical;
    }

    .num {
      clear: both;
      display: flex;
      height: 50px;
      align-items: center;
      font-size: 0.4rem;
      justify-content: space-between;
      color: #fa6400;
      margin: 10px;

      .doct {
        width: 70px;
        height: 34px;
        text-align: center;
        line-height: 34px;
        background: #1870f4;
        color: #fff;
        border-radius: 10px;
      }

      > div > span {
        color: #ccc;
        font-size: 0.3rem;
      }
    }

    .reviews {
      margin-top: 10px;
      font-size: 0.3rem;
      float: left;

      .color {
        color: #fa6400;
      }
    }

    .navs {
      display: flex;

      > div:nth-child(1) {
        width: 75px;
        height: 30px;
        border-radius: 10px;
        margin: 5px;
        line-height: 30px;
        text-align: center;
        background: #e7f0ff;
        color: #5892ff;
      }

      > div:nth-child(2) {
        width: 75px;
        height: 30px;
        margin: 5px;
        border-radius: 10px;
        line-height: 30px;
        text-align: center;
        color: #20c0af;
        background: #e4f7f2;
      }

      > div:nth-child(3) {
        width: 75px;
        height: 30px;
        margin: 5px;
        border-radius: 10px;
        line-height: 30px;
        text-align: center;
        color: #67cff9;
        background: #e5f7fd;
      }
    }

    .warp1 {
      display: flex;

      > h4 {
        margin: 0px 5px;
      }

      > div {
        margin-left: 10px;
      }
    }
  }
}
.tab-container {
  display: flex;
  .rigth {
    flex: 1;
  }
  .tabs .bg {
    height: 40px;
    background: #fff;
    line-height: 32px;
  }
  .tabs {
    width: 140px;
    background: #f7f8fa;
    height: 667px;
    overflow-y: auto;
    font-size: 0.3rem;
    > div {
      height: 40px;
      line-height: 32px;
    }
  }

  .tabs div {
    padding: 10px;
    cursor: pointer;
  }

  .tabs div.active {
    background-color: #ffffff;
    font-weight: bold;
  }

  .content {
    flex: 1;
    padding: 20px;
    width: 100%;
    height: 667px;
    overflow: scroll;
  }
  .rigth {
    width: 100%;
    height: 100vh;
    overflow-y: auto;
    .right-key {
      width: 150px;
      height: 20px;
      font-size: 0.4rem;
      height: 40px;
      line-height: 40px;
    }
  }
}
</style>